<?php

namespace App\Admin\Validate\Account;

use App\Common\Validate\BaseValidate;

/**
 * 权限组验证器
 */
class Company extends BaseValidate
{

    //验证规则
    protected $rule = [];
    //自定义验证信息
    protected $message = [];


    public function __construct($doaction = 'add')
    {
        if ($doaction == 'add') {
            $this->rule = [
                'p_code'=>'sometimes',
                'c_code'=>'sometimes',
                'd_code'=>'sometimes',
                'address_area'=>'sometimes',
                'company_name'=>'required',
                'account_name' => 'required|string|min:2|max:20',
                'contact_name' => 'required|string|min:2|max:20',
                'contact_phone' => ['required', 'regex:/^1[3-9]\d{9}$/'],
            ];
            $this->message = [
                'p_code.sometimes' => '省份未选择',
                'c_code.sometimes' => '城市未选择',
                'd_code.sometimes' => '区县未选择',
                'address_area.sometimes'=>'地址参数错误',
                'company_name.required' => '公司名称不能为空',
                'account_name.required' => '账号称不能为空',
                'account_name.min' => '账号长度不能小于2位',
                'account_name.max' => '账号长度不能大于20位',
                'contact_name.required' => '姓名不能为空',
                'contact_name.min' => '姓名长度不能小于2位',
                'contact_name.max' => '姓名长度不能大于20位',
                'contact_phone.required' => '用户手机号',
                'contact_phone.regex'=>'手机号不规范'
            ];
        } else {
            $this->rule = [
                'id' => 'required|integer|gt:0',
                'p_code.sometimes' => '省份未选择',
                'c_code.sometimes' => '城市未选择',
                'd_code.sometimes' => '区县未选择',
                'address_area.sometimes'=>'地址参数错误',
                'company_name'=>'required',
                'contact_name' => 'required|string|min:2|max:20',
                'contact_phone' => ['required', 'regex:/^1[3-9]\d{9}$/'],
            ];
            $this->message = [
                'id.required' => '公司参数错误',
                'id.integer' => '公司参数错误',
                'id.gt' => '公司参数错误',
                'p_code.sometimes' => '省份未选择',
                'c_code.sometimes' => '城市未选择',
                'd_code.sometimes' => '区县未选择',
                'address_area.sometimes'=>'地址参数错误',
                'company_name.required' => '公司名称不能为空',
                'contact_name.required' => '姓名不能为空',
                'contact_name.min' => '姓名长度不能小于2位',
                'contact_name.max' => '姓名长度不能大于20位',
                'contact_phone.required' => '用户手机号',
                'contact_phone.regex'=>'手机号不规范'
            ];
        }
    }
}
